import React from 'react';
import PropTypes from 'prop-types';
import { Modal, Radio, Form } from 'antd';

const RadioGroup = Radio.Group;


class UrgePersonModal extends React.Component {
    constructor(props) {
        super(props);
        this.state = {};
    }

    onOk = () => {
        const { form: { getFieldsValue }, onModalOk } = this.props;
        onModalOk(getFieldsValue());
    }

    renderRadio = () => {
        const { urgePerson } = this.props;
        return urgePerson.map((item, index) => <Radio value={item.value} key={index} >{item.name}</Radio>)
    }
    render() {
        const { visible, onModalCancel, form: { getFieldDecorator } } = this.props;
        return (
            <Modal
                onOk={this.onOk}
                onCancel={onModalCancel}
                width={400}
                visible={visible}
                title={'选择催收员'}
            >
                <div>
                    <Form>
                        <Form.Item lable={'催收人'}>
                            {
                                getFieldDecorator('person', {})(
                                    <RadioGroup>
                                        {this.renderRadio()}
                                    </RadioGroup>
                                )
                            }
                        </Form.Item>
                    </Form>
                </div>

            </Modal>
        );
    }
}
UrgePersonModal.propTypes = {
    visible: PropTypes.bool,
    onModalCancel: PropTypes.func,
    onModalOk: PropTypes.func,
    urgePerson: PropTypes.array,  //催收人
};
UrgePersonModal.defaultProps = {
    visible: false,
    urgePerson: [],
    onModalCancel() {},
    onModalOk() {}
};
export default Form.create({
    mapPropsToFields(props){
        const { urgePerson } = props;
        const isArr = Array.isArray(urgePerson) && urgePerson.length > 0;
        return {
            person: Form.createFormField({
                value: isArr ? urgePerson[0].value : ''
            })
        }
    }
})(UrgePersonModal);